package com.glsc.ngateway.flowable.listener.global;

import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.FormService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class ProcessCompleteListener extends AbstractFlowableEngineEventListener {

    private static Logger logger = LoggerFactory.getLogger(ProcessCompleteListener.class);


    @Autowired
    private TaskService taskService;
    @Autowired
    private FormService formService;
    @Autowired
    private RuntimeService runtimeService;

    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        logger.info("进入流程结束监听器……do something");

        String processInstanceId = event.getProcessInstanceId();
        Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
        Map<String, Object> startForm = (Map<String, Object>) variables.get("startForm");
        // Form form = formService..getById(new Long((String) startForm.get("formId")));

        logger.info("variables: " + variables);
        logger.info("startForm: " + startForm);
        // System.out.println("form: " + form);


        super.processCompleted(event);
    }


}